package com.frogs.ucenter.v1.controller;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.frogs.framework.base.web.BaseController3;
import com.frogs.system.web.api.response.FailResponse;
import com.frogs.system.web.api.response.Response;
import com.frogs.system.web.exception.AppBaseException;
import com.frogs.ucenter.v1.request.UserAttentionPraiseInfoRequest;
import com.frogs.ucenter.v1.request.UserAttentionPraiseListRequest;
import com.frogs.ucenter.v1.request.UserPersonalPraiseListRequest;
import com.frogs.ucenter.v1.request.UserPraiseInfoAddRequest;
import com.frogs.ucenter.v1.service.UserPraiseInfoService;
import com.frogs.ucenter.v1.util.ApiConstants;

@Controller(ApiConstants.VERSION + "userPraiseInfoController")
@RequestMapping("/" + ApiConstants.VERSION )
public class UserPraiseInfoController extends BaseController3 {
	
	private static final String USER_ATTENTION_PRAISE_LIST = "/user/praise/attention/list";
	
	private static final String USER_ATTENTION_PRAISE_INFO = "/user/praise/attention/info";
	/** 点赞,ajax*/
	private static final String USER_PRAISE = "/user/praise";
	/** 个人点赞列表,ajax*/
	private static final String USER_PRAISE_PERSONAL_LIST = "/user/praise/personal/list";

	@Resource(name= ApiConstants.VERSION + "userPraiseInfoService")
    private UserPraiseInfoService userPraiseInfoService;
	
	@RequestMapping(USER_ATTENTION_PRAISE_LIST)
    public Response getAttentionPraiseList(HttpServletRequest request) {
        Response response = null ; 
        try{
        	UserAttentionPraiseListRequest listRequest = new UserAttentionPraiseListRequest();
        	listRequest.parse(request);
        	response = userPraiseInfoService.getAttentionPraiseList(listRequest);
        }catch (Exception e) {
			response = new FailResponse();
			if (e instanceof AppBaseException) {
				response.setTip(e.getMessage());
			} else {
				response.setTip("errro message" + e.getMessage());
			}
		}
        return response;
    }
	
	@RequestMapping(USER_ATTENTION_PRAISE_INFO)
    public Response getAttentionPraiseInfo(HttpServletRequest request) {
        Response response = null ; 
        try{
        	UserAttentionPraiseInfoRequest infoRequest = new UserAttentionPraiseInfoRequest();
        	infoRequest.parse(request);
        	response = userPraiseInfoService.getAttentionPraiseInfo(infoRequest);
        }catch (Exception e) {
			response = new FailResponse();
			if (e instanceof AppBaseException) {
				response.setTip(e.getMessage());
			} else {
				response.setTip("errro message" + e.getMessage());
			}
		}
        return response;
    }
	
	@RequestMapping(USER_PRAISE)
	public Response doPraise(HttpServletRequest request) {
		Response response = null ; 
		try{
			UserPraiseInfoAddRequest req = new UserPraiseInfoAddRequest();
			req.parse(request);
			response = userPraiseInfoService.insertPraise(req);
		}catch (Exception e) {
			response = new FailResponse();
			if (e instanceof AppBaseException) {
				response.setTip(e.getMessage());
			} else {
				response.setTip("errro message" + e.getMessage());
			}
		}
		return response;
	}
	
	@RequestMapping(USER_PRAISE_PERSONAL_LIST)
	public Response getPraiseInfoList(HttpServletRequest request) {
		Response response = null ; 
		try{
        	UserPersonalPraiseListRequest listRequest = new UserPersonalPraiseListRequest();
        	listRequest.parse(request);
        	response = userPraiseInfoService.getPersonalPraiseInfo(listRequest);
		}catch (Exception e) {
			response = new FailResponse();
			if (e instanceof AppBaseException) {
				response.setTip(e.getMessage());
			} else {
				response.setTip("errro message" + e.getMessage());
			}
		}
		return response;
	}

}